import React from 'react';
import ProForm, { ProFormText } from '@ant-design/pro-form';
import { PageContainer } from '@ant-design/pro-layout';
import request from '@/utils/request';
import { message } from 'antd';

export default (): React.ReactNode => {
  
  function  modifyPwd(params:any) {
    return request('/xwyl/user/modifyPwd', {
      method: 'POST',
      requestType:'form',
      data: {
        ...params,
        method: 'post',
      },
    });
  }

  return (
    <PageContainer>
    <ProForm
      onFinish={async (values) => {
          if(values.pwd!=values.newPwd){
            message.warn('新密码输入不一致');
            return;
          }
          var val = await modifyPwd(values);
          if(val.errorCode==='200'){
            message.success(val.errorMessage);
          }else{
            message.error(val.errorMessage);
          }
      }}>
        <ProFormText width="md" name="loginName" label="登录名" placeholder="请输入登录名" rules={[{required: true}]} />
        <ProFormText.Password width="md" name="oldPwd" label="旧密码" placeholder="请输入旧密码" rules={[{required: true}]}/>
        <ProFormText.Password width="md" name="pwd" label="新密码" placeholder="请输入新密码" rules={[{required: true}]}/>
        <ProFormText.Password width="md" name="newPwd" label="确认新密码" placeholder="请再次输入新密码" rules={[{required: true}]}/>
      </ProForm>
    </PageContainer>
  );
};
